<template>
	<view class="transferRecord">
		<view class="header">
				<view class="authorized-header">
					<view class="authorized-head">
						<view :class="isRollIn==false?'au-title':''">
							<text @tap.stop="rollOut()">转出</text>
						</view>
						<view :class="isRollIn==true?'au-title':''">
							<text @tap.stop="rollIn()">转入</text>
						</view>
					</view>
					<view class="container" v-if="showContainer&&nodata==false">
						<uni-record
							:recordOut="recordOut"
							:isRollIn="isRollIn"
							@toTransferDetail="transferDetail"
							>
							</uni-record>
					</view>
					<uni-load-more
						v-if="isLoading"
						:status="loadingStatus" 
						iconType='auto' 
						:showIcon=true>
						</uni-load-more>
					<view class="nodata" v-if="nodata">
						<view class="msfont ms-wushuju">			
						</view>
						<view class="">
							无数据
						</view>
					</view>
				</view>
		</view>
	</view>
</template>

<script>
	import {transferList,rankExtent} from "@/common/api.js";
	import uniRecord from "@/components/uni-event/uni-record.vue"
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	export default{
		data(){
			return{
				isRollIn:false, //是否为转入
				type:0,
				page:{
					currentPage:1,
					pageSize:7
				},
				keyword:"",
				recordOut:[],
				showContainer:false,
				nodata:false,
				isLoading:false,
				loadingStatus:'loading'
			}
		},
		components:{
			uniRecord,
			uniLoadMore
		},
		onLoad() {
			var _this=this;
			_this.getRankExtent();
			uni.showLoading({
				title:"加载中..."
			})
			setTimeout(function(){
				_this.showContainer=true;
				uni.hideLoading()
			},1000)
		},
		onReachBottom() {
			var _this=this;
			_this.moreTransferData()
		},
		onPullDownRefresh(){
			var _this=this;
			_this.page.currentPage=1;
			_this.transferData=[];
			_this.getTransferData()
			setTimeout(function(){
				uni.stopPullDownRefresh()
			},1000)
		},
		methods:{
			//获取级别范围
			getRankExtent() {
				var _this = this;
				//测试
					// _this.rankSet.itemObject.step_1.push({type_name:'1级'},{type_name:"2级"})
					// _this.rankSet.itemObject.step_2.push([{type_name:'2级'},{type_name:"1级"}],[{type_name:'3级'},{type_name:"4级"}])
					
				rankExtent().then(function(res) {
					var e = res.data;
					if (e.errcode == 0) {
						if (e.data.length > 0) {
							_this.rank_arr=e.data;
							_this.type=0;							
							_this.getTransferData();
						}
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
							uni.showToast({
								position: 'center',
								icon: 'none',
								title:e.msg
							});
						}
				})
			},
			getData(){
				var _this=this;
				return{
					type:_this.type,
					pageSize:_this.page.pageSize,
					page:_this.page.currentPage,
					keywords:_this.keyword
				}
			},
			getTransferData(){
				var _this=this;
				var data=_this.getData()
				transferList(data).then(function(res){
					var e=res.data;
					if(e.errcode==0){
						e.data.map(function(item,index){
							item.gender=item.sex=="0"?"男":"女"
							item.time=item.create_time!=null?item.create_time.slice(0,4)+"年"+item.create_time.slice(5,7)+"月"+item.create_time.slice(8,10)+'日':"暂无"
							item.status=_this.checkState(item.transfer_state)
							_this.rank_arr.map(function(items,indexs){
								if(item.level==items.eventType_id){
									item.type_name=items.type_name
								}
							})
						})
						_this.recordOut=e.data;
						// if(_this.isRollIn){
						// 	e.total=0;
						// 	_this.recordOut=[]
						// }
						// console.log(_this.isLoading)
						_this.isLoading=Number(e.total)>_this.recordOut.length?true:false;
						// console.log(_this.isLoading)
						_this.page.currentPage+=1;
						_this.nodata=Number(e.total)==0?true:false;
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
							uni.showToast({
								position: 'center',
								icon: 'none',
								title:e.msg
							});
						}
				})
			},
			moreTransferData(){
				var _this=this;
				var data=_this.getData()
				transferList(data).then(function(res){
					var e=res.data;
					if(e.errcode==0){
						e.data.map(function(item,index){
							item.gender=item.sex=="0"?"男":"女"
							item.time=item.create_time!=null?item.create_time.slice(0,4)+"年"+item.create_time.slice(5,7)+"月"+item.create_time.slice(8,10)+'日':"暂无"
							item.status=_this.checkState(item.transfer_state)
							_this.rank_arr.map(function(items,indexs){
								if(item.level==items.eventType_id){
									item.type_name=items.type_name
								}
							})
						})
						_this.recordOut=_this.recordOut.concat(e.data);
						_this.isLoading=Number(e.total)>_this.recordOut.length?true:false;
						// if(Number(e.total)>_this.recordOut.length){
						_this.page.currentPage+=1;
						// }
					}else if(e.errcode==1000||e.errcode==1001){
							uni.removeStorageSync('token');
							uni.reLaunch({
								url:'/pages/home/welcome'
							})
						}else{
							uni.showToast({
								position: 'center',
								icon: 'none',
								title:e.msg
							});
						}
				})
			},
			checkState(state){
				if(state==1){
					return {text:"待处理",value:"warning"}
				}else if(state==2){
					return {text:"同意",value:"success"}
				}else if(state==4){
					return {text:"拒绝",value:"error"}
				}
			},
			rollOut(){
				var _this=this;
				_this.isRollIn=false;
				_this.type=0;
				_this.page.currentPage=1
				_this.getTransferData();
			},
			rollIn(){
				var _this=this;
				_this.isRollIn=true;
				_this.type=1;
				_this.page.currentPage=1;
				_this.getTransferData()
			},
			transferDetail(idcard,guid){
				var _this=this,rollIn=0;
				switch(_this.isRollIn){
					case true : 
						rollIn=0;break;
					case false :
						rollIn=1;break;
				}
				uni.navigateTo({
					url:"/pages/memberTransfer/transferDetail?idcard="+idcard+"&guid="+guid
				})
			}
		}
	}
</script>
<style lang="less" scoped>
	.header{
		background: #fff;
		height: 88rpx;
	}
	.authorized-head{
		display: flex;
		flex-direction: row;
		border-bottom: 2rpx solid #F6F7F9;
		view{
			color:#ACACAC;
			width: 50%;
			text-align: center;
			padding:10rpx 0 ;
			margin: 10rpx 0;
			font-size: 32rpx;
			position: relative;
			display: flex;
			justify-content: center;
		}
		.au-title{
			color: #333;
			width: 50%;
			text-align: center;
			padding:10rpx 0 ;
			font-size: 32rpx;
			position: relative;
			display: flex;
			justify-content: center;
			color: #1A66FF;
		}
		.au-title:after{
				content: "";
				width: 88rpx;
				height: 6rpx;
				background:#2D8DFF;
				position: absolute;
				bottom: 0;
				text-align: center;
			}
	}
	.nodata{
		position: fixed;
		top: 50%;
		left: 50%;
		margin-left: -117rpx;
		margin-top: -147rpx;
		.ms-wushuju{
			font-size: 150rpx;
			color: #ccc;
		}
		view:last-child{
			color: #aaa;
			text-align: center;
			margin-left: -20rpx;
			margin-top: -55rpx;
			font-size: 40rpx;
		}
	}
</style>
